<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <button  onclick="noticeSocket()">连接服务器</button>
    <p id="aaa">

    </p>
</div>
<script src="https://cdn.bootcss.com/sockjs-client/1.3.0/sockjs.min.js"></script>
<script>
    var noticeSocket = function () {
        // 订阅后加上 websocket

        var s = new SockJS('/socket');
        var stompClient = Stomp.over(s);
        stompClient.connect({}, function () {
            console.log('notice socket connected!');
            stompClient.subscribe('/topic/notice', function (data) {
                $('#aaa').html(data.body);
            });
        });
    };
</script>
</body>
</html>